package com.zsc.shixun.utils;

import com.zsc.shixun.model.unauthorize.MessageVO;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 消费者接收
 * </p>
 *
 * @author ZWYZY
 * @since 2020/6/11
 */
@Component
public class ConsumerUtils {
    @Autowired
    public MailUtils mailUtils;

    @RabbitListener(bindings = @QueueBinding(value = @Queue("code-queue"),
            exchange = @Exchange(value = "code_exchange", type = "fanout")))
    public void psubConsumerCodeAno(MessageVO messageVO) {
        mailUtils.sendCodeEmail(messageVO.getMailto(), messageVO.getTitle(), messageVO.getContent());
        System.out.println("验证码业务接收消息： " + messageVO);
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue("notice-queue"),
            exchange = @Exchange(value = "notice_exchange", type = "fanout")))
    public void psubConsumerSmsAno(MessageVO messageVO) {
        mailUtils.sendSimpleEmail(messageVO.getMailto(), messageVO.getTitle(), messageVO.getContent());

        System.out.println("通知注册业务接收消息： " + messageVO);
    }

}
